<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <!-- 搜索 -->
      <!-- <label class="el-form-item-label">年</label>
        <el-date-picker v-model="query.year" type="year" placeholder="选择年" value-format="yyyy"> </el-date-picker> -->
      <label class="el-form-item-label">月</label>
      <el-date-picker v-model="query.month" :disabled="!!query.jidu" placeholder="选择月" type="month" class="filter-item" value-format="yyyy-MM" @change="changeQuery" />
      <!-- <el-date-picker v-model="query.month" :disabled="!!query.beginDate" placeholder="选择月" type="monthrange" class="filter-item"  range-separator="-" start-placeholder="开始月份" end-placeholder="结束月份" value-format="yyyy-MM-31"> </el-date-picker>  -->
      <label class="el-form-item-label">季节</label>
      <el-date-picker v-model="query.jidu" :disabled="!!query.month" type="monthrange" align="right" class="filter-item" range-separator="-" start-placeholder="开始季节" end-placeholder="结束季节" :picker-options="pickerOptions" @change="changeQuery" />
      <rrOperation :crud="crud" />
      <el-button type="defalut" icon="el-icon-download" :loading="downloadLoading" style="float: right;" @click="doExport">导出</el-button>
    </div>
    <!--表格渲染-->
    <el-table ref="table" v-loading="listLoading" :data="crud.data" style="width: 100%;">
      <el-table-column :show-overflow-tooltip="true" type="index" label="序号" />
      <el-table-column :show-overflow-tooltip="true" prop="name" label="单位名称" />
      <el-table-column :show-overflow-tooltip="true" prop="engine" label="工作成效（50%）">
        <el-table-column :show-overflow-tooltip="true" prop="engine" label="问题扣分(发现的问题，省级层面每个问题扣0.3分，市级层面扣0.2分，县级层面静态问题扣0.1分，对发现问题督办后未整改到位的加一倍扣分，两次督办未整改到位的加两倍扣分）">
          <el-table-column :show-overflow-tooltip="true" prop="provincialNum" label="省级问题" />
          <el-table-column :show-overflow-tooltip="true" prop="cityIssuesNum" label="市级问题" />
          <el-table-column :show-overflow-tooltip="true" prop="countyIssuesNumfrom" label="县督导组发现问题" />
        </el-table-column>
      </el-table-column>
      <el-table-column :show-overflow-tooltip="true" prop="tableName" label=" ">
        <el-table-column :show-overflow-tooltip="true" prop="tableName" label="得分" />
      </el-table-column>
      <el-table-column :show-overflow-tooltip="true" prop="tableName" label="工作推进（20%） ">
        <el-table-column :show-overflow-tooltip="true" prop="tableName" label="环境卫生大扫除（未开展扣0.2分）" />
        <el-table-column :show-overflow-tooltip="true" prop="tableName" label="线、片、巷巡查（未开展巡查扣0.2分）">
          <el-table-column :show-overflow-tooltip="true" prop="tableName" label="第一周巡查" />
          <el-table-column :show-overflow-tooltip="true" prop="tableName" label="第二周巡查" />
          <el-table-column :show-overflow-tooltip="true" prop="tableName" label="第三周巡查" />
          <el-table-column :show-overflow-tooltip="true" prop="tableName" label="第四周巡查" />
        </el-table-column>
        <el-table-column :show-overflow-tooltip="true" prop="tableName" label="报送材料扣分（材料未按照 =要求报送扣0.2分）">
          <el-table-column :show-overflow-tooltip="true" prop="tableName" label="周报" />
          <el-table-column :show-overflow-tooltip="true" prop="tableName" label="网报" />
          <el-table-column :show-overflow-tooltip="true" prop="tableName" label="其他材料" />
        </el-table-column>
        <el-table-column :show-overflow-tooltip="true" prop="tableName" label="得分" />
      </el-table-column>
      <el-table-column :show-overflow-tooltip="true" prop="tableName" label="工作执行力（20%）">
        <el-table-column :show-overflow-tooltip="true" prop="tableName" label="未参会、代会碗工作落实情况不符合要求的，每次扣1分" />
      </el-table-column>
      <el-table-column :show-overflow-tooltip="true" prop="tableName" label="责任单位考核得分情况联创(10%)" />
      <el-table-column :show-overflow-tooltip="true" prop="tableName" label="加分项">
        <el-table-column :show-overflow-tooltip="true" prop="provincialRFNum" label="省级层面发现的动态问题，每5个整改到位加0.3分，每10个整改到位加0.6分，以此类推：" />
        <el-table-column :show-overflow-tooltip="true" prop="cityRFNum" label="市级层面发现的动态问题，每5个整改到位加0.2分，每10个整改到位加0.4分，以此类推：" />
        <el-table-column :show-overflow-tooltip="true" prop="countyRFNum" label="县级层面发现的动态问题，每5个整改到位加0.1分，每10个整改到位加0.2分 ，以此类推：" />
        <el-table-column :show-overflow-tooltip="true" prop="tableName" label="多项职能加分项(2个职能加0.5分，3个职能加1分)" />
        <el-table-column :show-overflow-tooltip="true" prop="tableName" label="有2个创建宿舍楼院的单位，当月创建单位宿舍楼院总分为平均分加0.1分;有3个创建宿舍楼院的单位，当月创建单位宿舍楼院总分为平均分加0.2分;" />
        <el-table-column :show-overflow-tooltip="true" prop="tableName" label="社会动员工作(前三单位分别加0.5分、0.3分、0.1分）" />
        <el-table-column :show-overflow-tooltip="true" prop="tableName" label="连续四周巡查工作获通报表扬加0.5分" />
      </el-table-column>
      <el-table-column :show-overflow-tooltip="true" prop="tableName" label="总分" />
      <el-table-column :show-overflow-tooltip="true" prop="tableName" label="排名" />
    </el-table>
    <!--分页组件-->
    <!-- <pagination /> -->
  </div>
</template>

<script>

import crudUnitAssess from '@/api/system/unitAssess'
import CRUD, { presenter, header, crud, form } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import pagination from '@crud/Pagination'
import { downloadFile } from '@/utils/index'
import { download } from '@/api/data'
import { getLastDay } from '@/utils/date.js'
const defaultForm = { id: null, name: null, description: null, dictDetails: [] }

export default {
  name: 'GeneratorIndex',
  components: { pagination, crudOperation, rrOperation },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  cruds() {
    const month = new Date().getFullYear() + '-' + (new Date().getMonth() + 1)
    return CRUD({ title: '责任单位考核得分情况', url: 'api/tEvent/selectUnitAssessment', query: {
      month: month,
      beginDate: month + '-01',
      endDate: month + '-' + getLastDay(month)
    }, crudMethod: { ...crudUnitAssess }})
  },
  data() {
    return {
      queryTypeOptions: [
        { key: 'name', display_name: '事件标题' }
      ],
      list: [],
      downloadLoading: false,
      listLoading: false,
      jidu: '',
      pickerOptions: {
        disabledDate(time) {
          return time.getTime()
        },
        shortcuts: [{
          text: '第一季节',
          onClick(picker) {
            this.jidu = '一季度'
            const start = new Date().getFullYear() + '-' + '01' + '-' + '01'
            const end = new Date().getFullYear() + '-' + '03' + '-' + '31'
            picker.$emit('pick', [start, end])
          }
        }, {
          text: '第二季节',
          onClick(picker) {
            this.jidu = '二季度'
            const start = new Date().getFullYear() + '-' + '04' + '-' + '01'
            const end = new Date().getFullYear() + '-' + '06' + '-' + '30'
            picker.$emit('pick', [start, end])
          }
        }, {
          text: '第三季节',
          onClick(picker) {
            this.jidu = '三季度'
            const start = new Date().getFullYear() + '-' + '07' + '-' + '01'
            const end = new Date().getFullYear() + '-' + '09' + '-' + '30'
            picker.$emit('pick', [start, end])
          }
        }, {
          text: '第四季节',
          onClick(picker) {
            this.jidu = '四季度'
            const start = new Date().getFullYear() + '-' + '10' + '-' + '01'
            const end = new Date().getFullYear() + '-' + '12' + '-' + '31'
            picker.$emit('pick', [start, end])
          }
        }]
      }
    }
  },
  created() {
    this.crud.optShow = { add: false, edit: false, del: false, download: false }
    // this.doList()
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true
    },
    changeQuery() {
      if (this.query.month) {
        delete this.query.jidu
        this.query.beginDate = this.query.month + '-01'
        this.query.endDate = this.query.month + '-' + getLastDay(this.query.month)
      } else if (this.query.jidu) {
        delete this.query.month
        this.query.beginDate = this.query.jidu[0]
        this.query.endDate = this.query.jidu[1]
      }
      this.crud.query = this.query
    },
    // doList(){
    //   this.listLoading = true
    //   crudUnitAssess.list(this.query).then((res)=>{
    //   this.listLoading = false
    //   this.list = res
    //   })
    // },
    doExport() {
      const that = this
      // if(!this.query.jidu&&!this.query.month){return this.$message.info('请选择查询条件')}
      this.downloadLoading = true
      const fileName = this.query.month ? this.query.month.split('-')[0] + '年' + this.query.month.split('-')[1] + '月' + '文明创建责任单位考核得分情况' : this.jidu + '文明创建责任单位考核得分情况'
      download('api/tEvent/downloadUnitAssessment', { ...this.query, strFileName: fileName }).then(result => {
        downloadFile(result, fileName, 'xlsx')
        this.downloadLoading = false
      }).catch(() => {
        this.downloadLoading = false
      })
    }
  }
}
</script>

<style scoped>

</style>
